import request from "@/utils/request";
import qs from "qs";
const COMMON_BASE_URL = "/api";

export const ComApiTableAPI = {
  getOffsetList(baseUrl: string, queryParams: ComApiTableQueryParams) {
    return request<any, ComApiTableListResponse[]>({
      url: `${COMMON_BASE_URL}${baseUrl}?${qs.stringify(queryParams, {
        arrayFormat: "repeat",
      })}`,
      method: "get",
    });
  },
  batchUpdate(baseUrl: string, data: BatchUpdateRequest[]) {
    return request<any, BatchOperationResponse[]>({
      url: `${COMMON_BASE_URL}${baseUrl}`,
      method: "post",
      data,
    });
  },
  batchReset(baseUrl: string, data: BatchResetRequest) {
    return request<any, BatchOperationResponse[]>({
      url: `${COMMON_BASE_URL}${baseUrl}`,
      method: "post",
      data,
    });
  },
  batchTrans(baseUrl: string, data: BatchTransRequest[]) {
    return request<any, BatchOperationResponse[]>({
      url: `${COMMON_BASE_URL}${baseUrl}`,
      method: "post",
      data,
    });
  },
  batchDelete(baseUrl: string, data: BatchDeleteRequest) {
    return request<any, BatchOperationResponse[]>({
      url: `${COMMON_BASE_URL}${baseUrl}`,
      method: "post",
      data,
    });
  },
  autoChannelSet(baseUrl: string, data: any) {
    return request<any, AutoChannelSetResponse>({
      url: `${COMMON_BASE_URL}${baseUrl}`,
      method: "post",
      data,
    });
  },
};

// 查询参数接口
export interface ComApiTableQueryParams {
  offset: number;
  limit: number;
  group: number[];
}

// 列表响应接口
export interface ComApiTableListResponse {
  [key: string]: any;
}

// 批量操作响应接口
export interface BatchOperationResponse {
  success: boolean;
  message?: string;
  data?: any;
}

// 批量更新请求接口
export interface BatchUpdateRequest {
  id: string | number;
  [key: string]: any;
}

// 批量重置请求接口
export interface BatchResetRequest {
  [key: string]: number[];
}

// 批量传动请求接口
export interface BatchTransRequest {
  [key: string]: any;
}

// 批量删除请求接口
export interface BatchDeleteRequest {
  [key: string]: number[];
}

// 自动调通道零漂和系数请求接口
// export interface AutoChannelSetRequest {
//   [key: string]: any;
// }

// 自动调通道零漂和系数响应接口
export interface AutoChannelSetResponse {
  cpu: number;
  type: number;
  status: string;
}
